/*
 * ParameterFunctionNode.cpp
 *
 *  Created on: 18/nov/2010
 *      Author: computer
 */
#include "DerivationTree.h"
#include "Expression.h"

ParameterFunctionNode::ParameterFunctionNode() : NodeTree_CRTP<ParameterFunctionNode>()  { }

ParameterFunctionNode::ParameterFunctionNode(const AutoPointer<NodeTree>& _left, const AutoPointer<NodeTree>& _right) : NodeTree_CRTP<ParameterFunctionNode>(), left(_left), right(_right) { }

ParameterFunctionNode::ParameterFunctionNode(const ParameterFunctionNode& copy) : NodeTree_CRTP<ParameterFunctionNode>(copy), left(copy.left), right(copy.right) { }

bool ParameterFunctionNode::execute(Pointer<LeonardVirtualMachine> LVM) {
	left->execute(LVM);
	if (!right.isNull()) {
		right->execute(LVM);
		AutoPointer<TreeExpression::Expression> second = LVM->top();
		LVM->pop();
		AutoPointer<TreeExpression::Expression> first = LVM->top() ;
		LVM->pop();
		first->setSon(second);
		LVM->push(first);
	}
	else {
		AutoPointer<TreeExpression::Expression> first = LVM->top() ;
		LVM->pop();
		LVM->push(first);
	}
	return true;
}

